import argparse


# 可选参数的值必须在指定的列表中(choices)

parser = argparse.ArgumentParser()
parser.add_argument('square', type=int,
                    help='display a square of a given number')
# parser.add_argument('-v', '--verbosity', type=int, help='increase output verbosity')
# choice 限定可选参数的选择【０，１，２】
parser.add_argument('-v', '--verbosity', type=int,
                    choices=[0, 1, 2], help='increase output verbosity')
args = parser.parse_args()
answer = args.square**2

# python argparse5.py #ERROR
# python argparse5.py 32
# python argparse5.py 32 -v 1
# python argparse5.py 32 -v 2
if args.verbosity == 2:
    print('The square of {} equals {}'.format(args.square, answer))
elif args.verbosity == 1:
    print('{}^2 == {}'.format(args.square, answer))
else:
    print(answer)
